package client;

import common.Email;
import common.LoginPassword;
import common.User;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Igor Demidov
 * Date: 25.02.13
 * Time: 18:01
 */
public class SendPageGUI {
    private JPanel panel1;
    private JButton sendButton;
    private JTextArea bodyTextArea;
    private JTextArea topicTextArea;
    private JTextArea recipientTextArea;

    public SendPageGUI(final MainClient client) {
        final JFrame frame = new JFrame("SendPageGUI");
        frame.setContentPane(this.panel1);
        frame.pack();
        frame.setVisible(true);
        bodyTextArea.setLineWrap(true);
        bodyTextArea.setWrapStyleWord(true);
        sendButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Email email = new Email(client.currentUserLogin, recipientTextArea.getText(),
                        new Date(), topicTextArea.getText(), bodyTextArea.getText());
                try {
                    frame.setVisible(false);
                    client.sendEmail(email);
                } catch (IOException e1) {
                    e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
        });
    }
}
